<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));




/** Custom loader */
function DeanAutoloader($file) {
	$logger = new Zend_Log(new Zend_Log_Writer_Stream('./app.log'));
	$logger->info('DeanAuloloader : ' .$file);
	
	if(strpos($file,"Omc") === 0) $pathFile = $file . ".php";
// 	elseif(strpos(strtolower($file),APPLICATION_NAME) === 0) $pathFile = APPLICATION_LIB_PATH . "/" . $file . ".php";
	elseif(strpos($file,"Logic") != false) $pathFile = APPLICATION_PATH . "/logics/" . $file . ".php";
	elseif(strpos($file,"Factory") != false) $pathFile = APPLICATION_PATH . "/factory/" . $file . ".php";
	elseif(strpos($file,"Model") != false) $pathFile = APPLICATION_PATH . "/models/" . $file . ".php";
	elseif(strpos($file,"Service") != false) $pathFile = APPLICATION_PATH . "/services/" . $file . ".php";
	elseif(strpos($file,"Controller") != false) $pathFile = APPLICATION_PATH . "/controllers/" . $file . ".php";
	elseif(strpos($file,"Adapter") != false) $pathFile = APPLICATION_PATH . "/adapters/" . $file . ".php";
	elseif(strpos($file,"Mock") != false) $pathFile = APPLICATION_PATH . "/../tests/mocks/" . $file . ".php";
	elseif(strpos($file,"Helper") != false) $pathFile = APPLICATION_PATH . "/views/helpers/" . $file . ".php";
	elseif(strpos($file,"Form") != false) $pathFile = APPLICATION_PATH . "/forms/" . $file . ".php";
	else require_once $file . ".php";
	
	$logger->info("Result : " . $pathFile);
	
	require_once $pathFile;
}

require_once 'Zend/Loader/Autoloader.php';
$zendLoader = Zend_Loader_Autoloader::getInstance();
$zendLoader->pushAutoloader('DeanAutoloader');



/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()->run();
